USE [QFsite]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_SYS_Department_Disabled]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[SYS_Department] DROP CONSTRAINT [DF_SYS_Department_Disabled]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_SYS_Privilege_LastModifiedTime]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[SYS_Privilege] DROP CONSTRAINT [DF_SYS_Privilege_LastModifiedTime]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_SYS_Role_LastModifiedTime]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[SYS_Role] DROP CONSTRAINT [DF_SYS_Role_LastModifiedTime]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_Users_CreateTime]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[SYS_User] DROP CONSTRAINT [DF_Users_CreateTime]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_SYS_User_Disabled]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[SYS_User] DROP CONSTRAINT [DF_SYS_User_Disabled]
END

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_Department]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_Department]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_Department]
GO

/****** Object:  Table [dbo].[SYS_EmplDept]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_EmplDept]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_EmplDept]
GO

/****** Object:  Table [dbo].[SYS_Employee]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_Employee]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_Employee]
GO

/****** Object:  Table [dbo].[SYS_Function]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_Function]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_Function]
GO

/****** Object:  Table [dbo].[SYS_Privilege]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_Privilege]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_Privilege]
GO

/****** Object:  Table [dbo].[SYS_PrivilegeItem]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_PrivilegeItem]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_PrivilegeItem]
GO

/****** Object:  Table [dbo].[SYS_Role]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_Role]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_Role]
GO

/****** Object:  Table [dbo].[SYS_RoleFunction]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_RoleFunction]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_RoleFunction]
GO

/****** Object:  Table [dbo].[SYS_RolePrivilege]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_RolePrivilege]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_RolePrivilege]
GO

/****** Object:  Table [dbo].[SYS_RoleUser]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_RoleUser]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_RoleUser]
GO

/****** Object:  Table [dbo].[SYS_User]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_User]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_User]
GO

/****** Object:  Table [dbo].[SYS_UserEmpl]    Script Date: 08/02/2011 21:13:28 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SYS_UserEmpl]') AND type in (N'U'))
DROP TABLE [dbo].[SYS_UserEmpl]
GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_Department]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_Department](
	[DeptID] [nvarchar](50) NOT NULL,
	[DeptName] [nvarchar](50) NULL,
	[DeptShortName] [nvarchar](50) NULL,
	[DeptDescr] [nvarchar](50) NULL,
	[DeptNo] [nvarchar](50) NULL,
	[DeptLevel] [int] NULL,
	[ParentID] [nvarchar](50) NULL,
	[CreateTime] [datetime] NULL,
	[Disabled] [int] NULL,
 CONSTRAINT [PK_SYS_Department] PRIMARY KEY CLUSTERED 
(
	[DeptID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_EmplDept]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_EmplDept](
	[EmplID] [nvarchar](50) NOT NULL,
	[DeptID] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_SYS_EmplDept] PRIMARY KEY CLUSTERED 
(
	[EmplID] ASC,
	[DeptID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_Employee]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_Employee](
	[EmplID] [nvarchar](50) NOT NULL,
	[EmplName] [nvarchar](50) NULL,
	[Sex] [nvarchar](50) NULL,
	[Birthday] [datetime] NULL,
	[Mobile] [nvarchar](50) NULL,
	[Phone1] [nvarchar](50) NULL,
	[Phone2] [nvarchar](50) NULL,
	[Email] [nvarchar](50) NULL,
	[Messenger] [nvarchar](50) NULL,
	[Address] [nvarchar](50) NULL,
	[IDCardNo] [nvarchar](50) NULL,
	[Description] [nvarchar](50) NULL,
	[Logo] [nvarchar](50) NULL,
	[Tag] [nvarchar](50) NULL,
	[CreateTime] [datetime] NULL,
	[Disabled] [int] NULL,
 CONSTRAINT [PK_SYS_Employee] PRIMARY KEY CLUSTERED 
(
	[EmplID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_Function]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_Function](
	[FunctionID] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](50) NULL,
	[Description] [nvarchar](50) NULL,
	[Tag] [nvarchar](50) NULL,
 CONSTRAINT [PK_SYS_Function] PRIMARY KEY CLUSTERED 
(
	[FunctionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_Privilege]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_Privilege](
	[PrivilegeID] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](50) NULL,
	[Description] [nvarchar](50) NULL,
	[Enabled] [bit] NULL,
	[LastModifiedTime] [datetime] NULL,
	[LastModifiedByID] [nvarchar](50) NULL,
 CONSTRAINT [PK_Privilege] PRIMARY KEY CLUSTERED 
(
	[PrivilegeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_PrivilegeItem]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_PrivilegeItem](
	[PrivilegeID] [nvarchar](50) NOT NULL,
	[ObjectID] [nvarchar](50) NOT NULL,
	[ActionCode] [nvarchar](50) NOT NULL,
	[ObjectType] [nvarchar](50) NULL,
 CONSTRAINT [PK_PrivilegeItem] PRIMARY KEY CLUSTERED 
(
	[PrivilegeID] ASC,
	[ObjectID] ASC,
	[ActionCode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_Role]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_Role](
	[RoleID] [nvarchar](50) NOT NULL,
	[Name] [nvarchar](50) NULL,
	[Description] [nvarchar](50) NULL,
	[LastModifiedTime] [datetime] NULL,
	[LastModifiedByID] [nvarchar](50) NULL,
	[Disabled] [int] NULL,
 CONSTRAINT [PK_SYS_Role] PRIMARY KEY CLUSTERED 
(
	[RoleID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_RoleFunction]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_RoleFunction](
	[RoleID] [nvarchar](50) NOT NULL,
	[FunctionID] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_SYS_RoleFunction] PRIMARY KEY CLUSTERED 
(
	[RoleID] ASC,
	[FunctionID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_RolePrivilege]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_RolePrivilege](
	[RoleID] [nvarchar](50) NOT NULL,
	[PrivilegeID] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_SYS_RolePrivilege] PRIMARY KEY CLUSTERED 
(
	[RoleID] ASC,
	[PrivilegeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_RoleUser]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_RoleUser](
	[RoleID] [nvarchar](50) NOT NULL,
	[UserName] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_SYS_RoleUser] PRIMARY KEY CLUSTERED 
(
	[RoleID] ASC,
	[UserName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_User]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_User](
	[UserName] [nvarchar](50) NOT NULL,
	[Password] [nvarchar](256) NULL,
	[LastModifiedTime] [datetime] NULL,
	[LastModifiedByID] [nvarchar](50) NULL,
	[LastRefresh] [datetime] NULL,
	[Disabled] [int] NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
	[UserName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [QFsite]
GO

/****** Object:  Table [dbo].[SYS_UserEmpl]    Script Date: 08/02/2011 21:13:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SYS_UserEmpl](
	[UserName] [nvarchar](50) NOT NULL,
	[EmplID] [nvarchar](50) NOT NULL
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[SYS_Department] ADD  CONSTRAINT [DF_SYS_Department_Disabled]  DEFAULT ((0)) FOR [Disabled]
GO

ALTER TABLE [dbo].[SYS_Privilege] ADD  CONSTRAINT [DF_SYS_Privilege_LastModifiedTime]  DEFAULT (getdate()) FOR [LastModifiedTime]
GO

ALTER TABLE [dbo].[SYS_Role] ADD  CONSTRAINT [DF_SYS_Role_LastModifiedTime]  DEFAULT (getdate()) FOR [LastModifiedTime]
GO

ALTER TABLE [dbo].[SYS_User] ADD  CONSTRAINT [DF_Users_CreateTime]  DEFAULT (getdate()) FOR [LastModifiedTime]
GO

ALTER TABLE [dbo].[SYS_User] ADD  CONSTRAINT [DF_SYS_User_Disabled]  DEFAULT ((0)) FOR [Disabled]
GO

